//
//  UIColor+DynamicColor.m
//  JKDynamicColor
//
//  Created by 王冲 on 2019/9/27.
//  Copyright © 2019 王冲. All rights reserved.
//

#import "UIColor+DynamicColor.h"
#import "UIColor+Extension.h"

@implementation UIColor (DynamicColor)


// MARK: - Public
/// 背景色
+ (UIColor *)jk_cardBackgroundColor {
    // 深色模式下阴影不能突出视图层次 需要比背景色浅
    if (@available(iOS 13.0, *)) {
        return [UIColor cy_dynamicColor:[UIColor whiteColor] darkColor:[UIColor tertiarySystemGroupedBackgroundColor]];
    } else {
        return [UIColor whiteColor];
    }
}

/// labelColor
+ (UIColor *)jk_labelColor {
    
    UIColor *normalColor = [[UIColor colorWithHexString:@"3C3C43"] colorWithAlphaComponent:0.3];
       if (@available(iOS 13.0, *)) {
           return [UIColor cy_dynamicColor:normalColor darkColor:[UIColor labelColor]];
       } else {
           return normalColor;
       }
}

// MARK: - Private
+ (UIColor *)cy_dynamicColor:(UIColor *)defaultColor
                   darkColor:(UIColor *)darkColor {
    if (@available(iOS 13.0, *)) {
        return [[UIColor alloc] initWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
                return darkColor;
            } else {
                return defaultColor;
            }
        }];
    } else {
        return defaultColor;
    }
}

@end
